﻿using System;
using System.Collections.Generic;
using System.Text;
using LBoL.Base;
using LBoL.Base.Extensions;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.EntityLib.Cards.Character.Marisa;
using LBoL.EntityLib.Cards.Neutral.Blue;
using LBoL.EntityLib.Cards.Neutral.NoColor;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;
using static ProbeMod.Cards.ProbeObserverDef;

namespace ProbeMod.Cards
{
    public sealed class ProbeRoboticsSupportDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Skill;
            config.Rarity = Rarity.Common;

            config.Colors = new List<ManaColor>() { ManaColor.White };
            config.Cost = new ManaGroup() { White = 2 };

            config.IsXCost = true;

            config.RelativeCards = new List<string>() { "ProbeObserver", "ProbeDragoon", "ProbeImmortal", "ProbeColossus" };
            config.UpgradedRelativeCards = new List<string>() { "ProbeObserver", "ProbeDragoon", "ProbeImmortal", "ProbeColossus" };

            config.Keywords = Keyword.Debut;
            config.UpgradedKeywords = Keyword.Debut;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }
    }

    /// <summary>
    /// 机械支援
    /// WWX
    /// 将ob置入战场 /初见：获得1张龙骑士
    /// 每支付3：将龙骑士置入手牌
    /// 每支付WWW：将不朽者置入手牌
    /// 每支付8：将强大的战争兵器巨像置入手牌，然后放逐此牌
    /// </summary>
    [EntityLogic(typeof(ProbeRoboticsSupportDef))]
    public sealed class ProbeRoboticsSupport : ProbeCard
    {
        protected override string GetBaseDescription()
        {
            if (base.DebutActive)
            {
                return base.GetBaseDescription();
            }
            return base.GetExtraDescription1;
        }

        // 获取X费
        public override ManaGroup GetXCostFromPooled(ManaGroup pooledMana)
        {
            return pooledMana;
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            //  给ob


            if (base.TriggeredAnyhow)
            {
                yield return new AddCardsToHandAction(Library.CreateCard<ProbeObserver>());
                if(IsUpgraded)
                    yield return new AddCardsToHandAction(Library.CreateCard<ProbeDragoon>());
            }


            var mana = base.PendingManaUsage.GetValueOrDefault();
            var dragoonCount = SynergyAmount(mana, ManaColor.Any)/3;
            var immortalCount = SynergyAmount(mana, ManaColor.White)/3;
            var colossus = SynergyAmount(mana, ManaColor.Any) / 8;

            yield return new AddCardsToHandAction(Library.CreateCards<ProbeDragoon>(dragoonCount));
            yield return new AddCardsToHandAction(Library.CreateCards<ProbeImmortal>(immortalCount));
            yield return new AddCardsToHandAction(Library.CreateCards<ProbeColossus>(colossus));

            if(colossus>0)
            {
                yield return new ExileCardAction(this);
            }
        }
    }
}
